package top.kaoshanji.s1ch17a.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import top.kaoshanji.s1ch17a.domain.User;

/**
 * 代码清单-s1ch17a-561页a：编写控制器
 * @author kaoshanji
 * ^_^
 * create time 2025/5/12 19:23
 */
@Controller
@RequestMapping("/user")
public class UserController {

    // 打开注册页面
    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public String register() {
        return "user/register";
    }

    // 提交注册
    @RequestMapping(value = "/createUser", method = RequestMethod.POST)
    public ModelAndView createUser(User user) {
        ModelAndView modelAndView = new ModelAndView();

        user.setUserId("101000");

        modelAndView.setViewName("user/createSuccess");
        modelAndView.addObject("user", user);

        System.out.println("...createUser：" + user);

        return modelAndView;
    }


}
